package com.example.backblog.controller.blog;



import com.alibaba.fastjson.JSONObject;
import com.example.backblog.apijson.DemoParser;
import com.example.backblog.dao.CategoryMapper;
import com.example.backblog.entity.blog.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController("/category")
public class CategoryController {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Autowired
    private CategoryMapper categoryMapper;
    @PostMapping("/add")
    public JSONObject addOne(@RequestBody Category category){
        int insert = categoryMapper.insert(category);
        // 同时修改数据库
        redisTemplate.delete("demo:listAll1::SimpleKey []");
        return DemoParser.newSuccessResult();
    }
    @PostMapping("/update")
    public JSONObject updateOne(@RequestBody Category category){
        int update = categoryMapper.updateById(category);
        redisTemplate.delete("demo:listAll1::SimpleKey []");
        return DemoParser.newSuccessResult();
    }
}
